package com.gw.vip.server.service.dao_service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gw.vip.server.dao.ViewTransMapper;
import com.gw.vip.server.po.ViewTrans;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author GW
 * @description
 * @since 2022-07-03
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ViewTransService extends ServiceImpl<ViewTransMapper, ViewTrans> {

    private final ViewTransMapper mapper;

    public IPage<ViewTrans> trans(String transId, String userId, String txnType, long current, long size) {
        QueryWrapper<ViewTrans> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(StringUtils.isNotBlank(transId), ViewTrans::getId, transId);
        queryWrapper.lambda().eq(StringUtils.isNotBlank(userId), ViewTrans::getUserId, userId);
        queryWrapper.lambda().eq(StringUtils.isNotBlank(txnType), ViewTrans::getTxnType, txnType);
        queryWrapper.select().orderByDesc("crt_time");
        Page<ViewTrans> page = new Page<>(current, size);
        return page(page, queryWrapper);
    }
}
